import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class studentUpdate {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource=new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/java104?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("666666");

        Connection connection=dataSource.getConnection();
        System.out.println(connection);

        Scanner scanner=new Scanner(System.in);
        System.out.println("输入要更改学生的学号");
        int id=scanner.nextInt();
        System.out.println("输入学生的新名字");
        String name=scanner.next();
        String sql="update student set  name=? where id=?";
        PreparedStatement ps=connection.prepareStatement(sql);
        ps.setInt(2,id);
        ps.setString(1,name);
        ps.executeUpdate();

        ps.close();
        connection.close();
    }
}
